package com.beta.dto.cart;

import com.beta.dto.product.ProductItemOptions;
import com.beta.dto.product.ProductPropertiesDto;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/**
 * Created by lichao on 2016/11/17.
 */
@Getter
@Setter
public class CartItemDto implements Serializable {


    private static final long serialVersionUID = -2501067475094874788L;

    private Integer id;

    private String name;

    private Integer quantity;

    private BigDecimal price;

    private String userName;

    private String chargeUnit;

    private Integer maxQty;

    private Integer minQty;

    private Integer productId;

    private Integer productItemId;

    private String productPoster;

    private Integer assetId;

    private String assetImage;

    private List<ProductPropertiesDto> properties;

    private List<ProductItemOptions> options;

    public String getPosterUrl() {
        if (StringUtils.isNoneBlank(getAssetImage())) {
            return String.join("/", "image", "attachment", Objects.toString(getAssetId()), getAssetImage());
        }
        return String.join("/", "product", "poster", Objects.toString(this.getProductId()), this.getProductPoster());
    }

    public String getOrigin() {
        if (CollectionUtils.isEmpty(properties)) {
            return "";
        }
        for (ProductPropertiesDto pro : properties) {
            if (pro.getName().equals("origin")) {
                return pro.getValue();
            }
        }
        return "";
    }

    public String getLevel() {
        if (CollectionUtils.isEmpty(options)) {
            return "";
        }

        for (ProductItemOptions pro : options) {
            if (pro.getName().equals("level"))
                return pro.getValuePresentation();
        }
        return "";
    }

}
